import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)


import Login from '@/views/login'
import Layout from '@/layout/Layout.vue'


const VueRouterPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(to) {
  return VueRouterPush.call(this, to).catch(err => err)
}

const routes = []

// const routes = [
//   {
//     path: '/',
//     redirect: '/home'
//   },
//   //登录
//   {
//     path: '/login',
//     component: Login
//   },
//   // 首页
//   {
//     path: '/home',
//     component: Layout,
//     meta: { path: '/home', title: '首页' },
//     children: [
//       {
//         path: '',
//         component: () => import('@/views/home')
//       }
//     ]
//   },
//   // 订单管理
//   {
//     path: '/order',
//     component: Layout,
//     meta: { path: '/order', title: '订单管理' },
//     children: [
//       {
//         path: '',
//         component: () => import('@/views/order')
//       },
//       {
//         path: '/order/order-details',
//         component: () => import('@/views/order/order-details')
//       },
//       {
//         path: '/order/order-edit/:id',
//         component: () => import('@/views/order/order-edit')
//       },
//     ]
//   },
//   // 店铺管理
//   {
//     path: '/shop',
//     component: Layout,
//     meta: { path: '/shop', title: '店铺管理' },
//     children: [
//       {
//         path: '',
//         component: () => import('@/views/shop')
//       }
//     ]
//   },
//   // 商品管理
//   {
//     path: '/goods',
//     component: Layout,
//     redirect: '/goods/goods-list',
//     meta: { path: '/goods', title: '商品管理' },
//     children: [
//       {
//         meta: { path: '/goods/goods-list', title: '商品列表' },
//         path: '/goods/goods-list',
//         component: () => import('@/views/goods/goods-list')
//       },
//       {
//         meta: { path: '/goods/goods-cate', title: '商品分类' },
//         path: '/goods/goods-cate',
//         component: () => import('@/views/goods/goods-cate')
//       },
//       {
//         meta: { path: '/goods/goods-add', title: '商品添加' },
//         path: '/goods/goods-add',
//         component: () => import('@/views/goods/goods-add')
//       }
//     ]
//   },
//   // 账号管理
//   {
//     path: '/account',
//     component: Layout,
//     redirect: '/account/account-list',
//     meta: { path: '/account', title: '账号管理' },
//     children: [
//       {
//         meta: { path: '/account/account-list', title: '账号列表' },
//         path: '/account/account-list',
//         component: () => import('@/views/account/account-list')
//       },
//       {
//         meta: { path: '/account/account-add', title: '账号添加' },
//         path: '/account/account-add',
//         component: () => import('@/views/account/account-add')
//       },
//       {
//         meta: { path: '/account/password', title: '修改密码' },
//         path: '/account/password',
//         component: () => import('@/views/account/password-modify')
//       },
//       {
//         meta: { path: '/account/account-person', title: '个人中心' },
//         path: '/account/account-person',
//         component: () => import('@/views/account/account-person')
//       }
//     ]
//   },
//   // 销售统计
//   {
//     path: '/total',
//     component: Layout,
//     meta: { path: '/total', title: '销售统计' },
//     redirect: '/total/total-goods',
//     children: [
//       {
//         meta: { path: '/total/total-goods', title: '商品统计' },
//         path: '/total/total-goods',
//         component: () => import('@/views/total/total-goods')
//       },
//       {
//         meta: { path: '/total/total-order', title: '订单统计' },
//         path: '/total/total-order',
//         component: () => import('@/views/total/total-order')
//       }
//     ]
//   },
//   //404
//   {
//     path: '*',
//     redirect: '/404',
//   },
//   {
//     path: '/404',
//     component: () => import('@/views/404/error404.vue')
//   }
// ]
//静态路由
export const constantRoutes = [
  {
    path: '/',
    redirect: '/home'
  },
  //   //登录
  {
    path: '/login',
    component: Login
  },
  //   // 首页
  {
    path: '/home',
    component: Layout,
    meta: { path: '/home', title: '首页',icon:'home' },
    children: [
      {
        path: '',
        component: () => import('@/views/home')
      }
    ]
  },
]

//动态路由
export const asnycRoutes = [
  // 订单管理
  {
    path: '/order',
    component: Layout,
    meta: { path: '/order', title: '订单管理', roles: ['super'],icon:'dingdan' },
    children: [
      {
        path: '',
        component: () => import('@/views/order')
      },
      {
        path: '/order/order-details',
        component: () => import('@/views/order/order-details')
      },
      {
        path: '/order/order-edit/:id',
        component: () => import('@/views/order/order-edit')
      },
    ]
  },
  //   // 店铺管理
  {
    path: '/shop',
    component: Layout,
    meta: { path: '/shop', title: '店铺管理', roles: ['super'],icon:'dianpu' },
    children: [
      {
        path: '',
        component: () => import('@/views/shop')
      }
    ]
  },
  //   // 商品管理
  {
    path: '/goods',
    component: Layout,
    redirect: '/goods/goods-list',
    meta: { path: '/goods', title: '商品管理',icon:'shangpin' },
    children: [
      {
        meta: { path: '/goods/goods-list', title: '商品列表' },
        path: '/goods/goods-list',
        component: () => import('@/views/goods/goods-list')
      },
      {
        meta: { path: '/goods/goods-cate', title: '商品分类' },
        path: '/goods/goods-cate',
        component: () => import('@/views/goods/goods-cate')
      },
      {
        meta: { path: '/goods/goods-add', title: '商品添加', roles: ['super'] },
        path: '/goods/goods-add',
        component: () => import('@/views/goods/goods-add')
      }
    ]
  },
  //   // 账号管理
  {
    path: '/account',
    component: Layout,
    redirect: '/account/account-list',
    meta: { path: '/account', title: '账号管理' ,icon:'zhanghao'},
    children: [
      {
        meta: { path: '/account/account-list', title: '账号列表', roles: ['super'] },
        path: '/account/account-list',
        component: () => import('@/views/account/account-list')
      },
      {
        meta: { path: '/account/account-add', title: '账号添加', roles: ['super'] },
        path: '/account/account-add',
        component: () => import('@/views/account/account-add')
      },
      {
        meta: { path: '/account/password', title: '修改密码' },
        path: '/account/password',
        component: () => import('@/views/account/password-modify')
      },
      {
        meta: { path: '/account/account-person', title: '个人中心' },
        path: '/account/account-person',
        component: () => import('@/views/account/account-person')
      }
    ]
  },
  //   // 销售统计
  {
    path: '/total',
    component: Layout,
    meta: { path: '/total', title: '销售统计', roles: ['super'],icon:'bingzhuangtu' },
    redirect: '/total/total-goods',
    children: [
      {
        meta: { path: '/total/total-goods', title: '商品统计' },
        path: '/total/total-goods',
        component: () => import('@/views/total/total-goods')
      },
      {
        meta: { path: '/total/total-order', title: '订单统计' },
        path: '/total/total-order',
        component: () => import('@/views/total/total-order')
      }
    ]
  },
]

//错误路由
export const errorRoutes = [
  //404
  {
    path: '*',
    redirect: '/404',
  },
  {
    path: '/404',
    component: () => import('@/views/404/error404.vue')
  }
]

const router = new VueRouter({
  routes: constantRoutes, 
})

export default router
